/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mixsound;

import component.ButtonForward;
import component.ButtonPlay;
import component.ButtonRewind;

import Helper.TimerHelper;
import com.dhchoi.CountdownTimer;

import component.LeftJogPart;
import component.RightJogPart;
import component.SoundTimer;
import controlP5.ControlEvent;
import controlP5.ListBox;
import ddf.minim.AudioPlayer;
import ddf.minim.*;
import processing.core.PApplet;

/**
 *
 * @author Caliste
 */
public class MixSound extends PApplet{
    
    private LeftJogPart     _leftPart;
    private RightJogPart    _rightPart;
    // Pour instancier le player
    public Minim        _leftMinim;
    public Minim        _rightMinim;
    
    private CountdownTimer _timerLeft;
    
    // Les boutons
    private ButtonPlay    _play;
    private ButtonRewind  _rewind;
    private ButtonForward _ffwd;
    
    @Override
    public void setup()
    {
        // On initialise la taille de la fenetre
        size(800, 600, P3D);
        // On initialise "la partie gauche"
        _leftPart   = new LeftJogPart(this);
        // On initialise "la partie droite"
        _rightPart   = new RightJogPart(this);
        // On recupère une instance de Minim pour travailler avec le son
        //_leftMinim      = new Minim(this);
        //_rightMinim      = new Minim(this);
        //_platine1 = new LeftTurntable(30, 225, 200, 200, this);

        // On instancie les 3 boutons
//            _play = new ButtonPlay(400, 130, 20, 10, this, _leftPlayer);
//            _rewind = new ButtonRewind(500, 130, 20, 10, this, _leftPlayer);
//            _ffwd = new ButtonForward(600 , 130, 20, 10, this, _leftPlayer);
    }
  
    @Override
    public void draw()
    {
        //background(r,g,b)
        background(131, 183, 228); // bleu
        // remplir en gris le rectangle
        fill(100);
        //. création du rectangle de gauche
        rect(10, 10, 300, 580);
        //. création du rectangle de droite
        rect(410, 10, 300, 580);
        
//        for (int i = 0; i < _leftPlayer.bufferSize() - 1;  i++)
//        {
//          line(i, 50 - _leftPlayer.left.get(i)*50, i+1, 50 - _leftPlayer.left.get(i+1)*10);
//        }
//        // draw the position in the song
//        // the position is in milliseconds,
//        // to get a meaningful graphic, we need to map the value to the range [0, width]
//        float x = map(_leftPlayer.position(), 0, _leftPlayer.length(), 0, width);
//        stroke(255, 0, 0);
//        line(x, 50 - 20, x, 50 + 20);
//        
//        _play.update();
//        _play.draw();
//        _rewind.update();
//        _rewind.draw();
//        _ffwd.update(); 
//        _ffwd.draw();
        
        _leftPart.getPlatine().draw();
        _rightPart.getPlatine().draw();   
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        PApplet.main(new String[] 
        {
            "mixsound.MixSound"
        });
    }
    
    /**
     * Dans cette méthode, les "listeners" (chaque 'if' correspond à
     * un "listener")
     * 
     * @param event 
     */
    public void controlEvent(ControlEvent event) 
    {    
        _leftPart.controlEvent(event);
        _rightPart.controlEvent(event);
    }

    public void onTickEvent(int timerId, long timeLeftUntilFinish) 
    {
        _leftPart.onTickEvent(timerId, timeLeftUntilFinish);
        _rightPart.onTickEvent(timerId, timeLeftUntilFinish);
    }

    public void onFinishEvent(int timerId) 
    {
        _leftPart.onFinishEvent(timerId);
        _rightPart.onFinishEvent(timerId);
    }
    
    public void mousePressed()
    {     
//      _play.mousePressed();
//      _rewind.mousePressed();
//      _ffwd.mousePressed();
      _leftPart.getPlatine().mousePressed();
    }

    public void mouseReleased()
    {
//      _play.mouseReleased();
//      _rewind.mouseReleased();
//      _ffwd.mouseReleased();
      _leftPart.getPlatine().mouseReleased();
    }
}
